﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.ComponentModel;
using System.Reflection;

namespace ProcessMonitor
{
    /// <summary>
    /// Interaction logic for ConfigWindow.xaml
    /// </summary>
    public partial class ConfigWindow : Window, INotifyPropertyChanged
    {
        private static ConfigWindow _instance;
        private bool shuttingDown;

        private double _bytesRead;
        public double BytesRead
        {
            get { return _bytesRead; }
            set
            {
                _bytesRead = value;
                NotifyPropertyChanged("BytesRead");
            }
        }

        private double _bytesWrite;
        public double BytesWrite
        {
            get { return _bytesWrite; }
            set
            {
                _bytesWrite = value;
                NotifyPropertyChanged("BytesWrite");
            }
        }

        private double _netSent;
        public double NetSent
        {
            get { return _netSent; }
            set
            {
                _netSent = value;
                NotifyPropertyChanged("NetSent");
            }
        }

        private double _netReceived;
        public double NetReceived
        {
            get { return _netReceived; }
            set
            {
                _netReceived = value;
                NotifyPropertyChanged("NetReceived");
            }
        }

        private double _processing;
        public double Processing
        {
            get { return _processing; }
            set
            {
                _processing = value;
                NotifyPropertyChanged("Processing");
            }
        }

        private ConfigWindow()
        {
            InitializeComponent();

            this.DataContext = this;

            shuttingDown = false;
            this.Closing += UserInteractionDialog_Closing;
            Application.Current.MainWindow.Closing += OnMainWindowClosing;

            this.Processing = 0.0007;
            this.BytesRead = 0;
            this.BytesWrite = 0;
        }

        public static ConfigWindow Instance
        {
            get
            {
                if (_instance == null)
                    _instance = new ConfigWindow();

                return _instance;
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;
        private void NotifyPropertyChanged(string p)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(p));
            }
        }

        private void CloseButton_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }
 
        private void OnMainWindowClosing(object sender, System.ComponentModel.CancelEventArgs e) 
        { 
            shuttingDown = true; 
            this.Close(); 
        } 
 
        private void UserInteractionDialog_Closing(object sender, System.ComponentModel.CancelEventArgs e) 
        { 
            if (!shuttingDown) 
            { 
                e.Cancel = true; 
                this.Hide(); 
            } 
        } 
    }
}
